<!DOCTYPE html>
<html>
<head>
<title>隐患添加</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport"
	content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="format-detection" content="telephone=no" />
<meta charset="utf-8" />
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="json2.js"></script>
<style type="text/css">
body, html, #allmap {
	width: 100%;
	height: 100%;
	margin: 0;
	font-family: "微软雅黑";
}
</style>
<script type="text/javascript"
	src="http://api.map.baidu.com/api?v=2.0&ak=cR98TwX2FnKTpANIOYhMYMot9a4ioxjc"></script>
<script type="text/javascript"
	src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
</head>
<span> 管理分区 : </span>
<select id="select1" onchange="gradeChange()"></select>
<span>&nbsp;&nbsp; 房屋类型 : </span>
<select id="select2" onchange="gradeChange()"></select>
<span>&nbsp;&nbsp; 状态 : </span>
<select id="select3" onchange="gradeChange()"></select>
<span>&nbsp;&nbsp; 房租 : </span>
<select id="select4" onchange="gradeChange()"></select>
<span>&nbsp;&nbsp; 房屋等级 : </span>
<select id="select5" onchange="gradeChange()"></select>
<span>&nbsp;&nbsp; 经营项目 : </span>
<select id="select6" onchange="gradeChange()"></select>

<span id="total"></span>
<div id="allmap"></div>
<body>
</body>
</html>
<style type="text/css">
</style>

<script type="text/javascript">
	var xhm = new ActiveXObject("Microsoft.XMLHttp");
	xhm.open("GET", "../baiduMap/getManageRegion.do", false);
	xhm.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhm.send();
	var roomInfos = JSON.parse(xhm.responseText);

	// 创建一个DOM元素
	var select1 = document.getElementById("select1");

	var option = document.createElement("option");
	option.innerHTML = "全部";
	option.setAttribute("value", "");
	select1.appendChild(option);
	for (var i = 0; i < roomInfos.length; i++) {
		if (roomInfos[i].manageRegion != "") {
			var option = document.createElement("option");
			option.innerHTML = roomInfos[i].manageRegion;
			option.setAttribute("value", roomInfos[i].manageRegion);
			select1.appendChild(option);
		}
	}

	var xhm = new ActiveXObject("Microsoft.XMLHttp");
	xhm.open("GET", "../baiduMap/getRoomProperty.do", false);
	xhm.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhm.send();
	var roomInfos = JSON.parse(xhm.responseText);

	var select2 = document.getElementById("select2");

	var option = document.createElement("option");
	option.innerHTML = "全部";
	option.setAttribute("value", "");
	select2.appendChild(option);
	for (var i = 0; i < roomInfos.length; i++) {
		if (roomInfos[i].manageRegion != "") {
			var option = document.createElement("option");
			option.innerHTML = roomInfos[i].roomProperty;
			option.setAttribute("value", roomInfos[i].roomProperty);
			select2.appendChild(option);
		}
	}

	var select3 = document.getElementById("select3");

	var option = document.createElement("option");
	option.innerHTML = "全部";
	option.setAttribute("value", "");
	select3.appendChild(option);

	var option = document.createElement("option");
	option.innerHTML = "已出租";
	option.setAttribute("value", "已出租");
	select3.appendChild(option);

	var option = document.createElement("option");
	option.innerHTML = "空置";
	option.setAttribute("value", "空置");
	select3.appendChild(option);

	var option = document.createElement("option");
	option.innerHTML = "不可出租";
	option.setAttribute("value", "不可出租");
	select3.appendChild(option);

	var select4 = document.getElementById("select4");

	var option = document.createElement("option");
	option.innerHTML = "全部";
	option.setAttribute("value", "");
	select4.appendChild(option);

	var option = document.createElement("option");
	option.innerHTML = "0-100";
	option.setAttribute("value", "0");
	select4.appendChild(option);

	var option = document.createElement("option");
	option.innerHTML = "100-500";
	option.setAttribute("value", "1");
	select4.appendChild(option);

	var option = document.createElement("option");
	option.innerHTML = "500-1000";
	option.setAttribute("value", "2");
	select4.appendChild(option);

	var option = document.createElement("option");
	option.innerHTML = "1000-3000";
	option.setAttribute("value", "3");
	select4.appendChild(option);

	var option = document.createElement("option");
	option.innerHTML = "3000-5000";
	option.setAttribute("value", "4");
	select4.appendChild(option);

	var option = document.createElement("option");
	option.innerHTML = "5000-10000";
	option.setAttribute("value", "5");
	select4.appendChild(option);

	var option = document.createElement("option");
	option.innerHTML = ">10000";
	option.setAttribute("value", "6");
	select4.appendChild(option);

	var xhm = new ActiveXObject("Microsoft.XMLHttp");
	xhm.open("GET", "../baiduMap/getDangerClassification.do", false);
	xhm.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhm.send();
	var roomInfos = JSON.parse(xhm.responseText);

	var select5 = document.getElementById("select5");

	var option = document.createElement("option");
	option.innerHTML = "全部";
	option.setAttribute("value", "");
	select5.appendChild(option);
	for (var i = 0; i < roomInfos.length; i++) {
		if (roomInfos[i].dangerClassification != ""
				&& roomInfos[i].dangerClassification != null) {
			var option = document.createElement("option");
			option.innerHTML = roomInfos[i].dangerClassification;
			option.setAttribute("value", roomInfos[i].dangerClassification);
			select5.appendChild(option);
		}
	}

	var xhm = new ActiveXObject("Microsoft.XMLHttp");
	xhm.open("GET", "../baiduMap/getFareItem.do", false);
	xhm.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhm.send();
	var chartInfos = JSON.parse(xhm.responseText);

	var select6 = document.getElementById("select6");

	var option = document.createElement("option");
	option.innerHTML = "全部";
	option.setAttribute("value", "");
	select6.appendChild(option);
	for (var i = 0; i < chartInfos.length; i++) {
		if (chartInfos[i].fareItem != "") {
			var option = document.createElement("option");
			option.innerHTML = chartInfos[i].fareItem;
			option.setAttribute("value", chartInfos[i].fareItem);
			select6.appendChild(option);
		}
	}

	function gradeChange() {
		var objS1 = document.getElementById("select1");
		var grade1 = objS1.options[objS1.selectedIndex].value;
		//console.log(objS.options[objS.selectedIndex]);
		grade1 = encodeURI(encodeURI(grade1));
		//alert(grade); 

		var objS2 = document.getElementById("select2");
		var grade2 = objS2.options[objS2.selectedIndex].value;
		//console.log(objS.options[objS.selectedIndex]);
		grade2 = encodeURI(encodeURI(grade2));

		var objS3 = document.getElementById("select3");
		var grade3 = objS3.options[objS3.selectedIndex].value;
		//console.log(objS.options[objS.selectedIndex]);
		grade3 = encodeURI(encodeURI(grade3));

		var objS4 = document.getElementById("select4");
		var grade4 = objS4.options[objS4.selectedIndex].value;
		//console.log(objS.options[objS.selectedIndex]);
		grade4 = encodeURI(encodeURI(grade4));

		var objS5 = document.getElementById("select5");
		var grade5 = objS5.options[objS5.selectedIndex].value;
		//console.log(objS.options[objS.selectedIndex]);
		grade5 = encodeURI(encodeURI(grade5));

		var objS6 = document.getElementById("select6");
		var grade6 = objS6.options[objS6.selectedIndex].value;
		//console.log(objS.options[objS.selectedIndex]);
		grade6 = encodeURI(encodeURI(grade6));

		map.clearOverlays();
		if (grade1 != "" || grade2 != "" || grade3 != "" || grade4 != ""
				|| grade5 != "" || grade6 != "") {
			var xhm = new ActiveXObject("Microsoft.XMLHttp");
			xhm.open("GET", "../baiduMap/getAllAsset.do?manageRegion=" + grade1
					+ "&roomProperty=" + grade2 + "&state=" + grade3 + "&hire="
					+ grade4 + "&dangerClassification=" + grade5 + "&fareItem="
					+ grade6, false);
			xhm.setRequestHeader("Content-type",
					"application/x-www-form-urlencoded");
			xhm.send();
			var ticket = JSON.parse(xhm.responseText);

			var data = JSON.parse(xhm.responseText);
			var ticket = data.rows;

			var total = document.getElementById("total");
			total.innerHTML = "&nbsp;&nbsp;总共 : " + data.total;

			addDeck(ticket);

		} else {

			var xhm = new ActiveXObject("Microsoft.XMLHttp");
			xhm.open("GET", "../baiduMap/getAllAssetPosition.do", false);
			xhm.setRequestHeader("Content-type",
					"application/x-www-form-urlencoded");
			xhm.send();
			var ticket = JSON.parse(xhm.responseText);

			var data = JSON.parse(xhm.responseText);
			var ticket = data.rows;

			var total = document.getElementById("total");
			total.innerHTML = "&nbsp;&nbsp;总共 : " + data.total;

			addDeck(ticket);

			var xhm = new ActiveXObject("Microsoft.XMLHttp");
			xhm.open("GET", "../baiduMap/getAllAsset.do?roomProperty="
					+ encodeURI(encodeURI("住宅房")), false);
			xhm.setRequestHeader("Content-type",
					"application/x-www-form-urlencoded");
			xhm.send();
			var data2 = JSON.parse(xhm.responseText);
			var ticket2 = data2.rows;

			addDeck2(ticket2);

		}

	}

	function addDeck(ticket) {

		// console.log(ticket);
		var json_data = new Array();

		for (var i = 0; i < ticket.length; i++) {
			json_data[i] = [ ticket[i].lng, ticket[i].lat, ticket[i].address ];
		}

		var pointArray = new Array();

		for (var i = 0; i < json_data.length; i++) {
			var point = new BMap.Point(json_data[i][0], json_data[i][1]);
			var myIcon = new BMap.Icon("../img/blackPoint.jpg", new BMap.Size(
					10, 30));
			var marker = new BMap.Marker(point, {
				icon : myIcon
			}); // 创建点
			map.addOverlay(marker); //增加点	
			pointArray[i] = new BMap.Point(json_data[i][0], json_data[i][1]);
			marker.addEventListener("click", addEvent);
		}

		map.setViewport(pointArray);

	}

	function addDeck2(ticket) {

		// console.log(ticket);
		var json_data = new Array();

		for (var i = 0; i < ticket.length; i++) {
			json_data[i] = [ ticket[i].lng, ticket[i].lat, ticket[i].address ];
		}

		var pointArray = new Array();

		for (var i = 0; i < json_data.length; i++) {
			var point = new BMap.Point(json_data[i][0], json_data[i][1]);
			var myIcon = new BMap.Icon("../img/blackPoint2.png", new BMap.Size(
					10, 30));
			var marker = new BMap.Marker(point, {
				icon : myIcon
			});// 创建点
			map.addOverlay(marker); //增加点	
			pointArray[i] = new BMap.Point(json_data[i][0], json_data[i][1]);
			marker.addEventListener("click", addEvent);
		}

		map.setViewport(pointArray);

	}

	function addDeck3(ticket) {

		// console.log(ticket);
		var json_data = new Array();

		for (var i = 0; i < ticket.length; i++) {
			json_data[i] = [ ticket[i].lng, ticket[i].lat, ticket[i].address ];
		}

		var pointArray = new Array();

		for (var i = 0; i < json_data.length; i++) {
			var point = new BMap.Point(json_data[i][0], json_data[i][1]);
			var myIcon = new BMap.Icon("../img/hidden.jpg", new BMap.Size(10,
					30));
			var marker = new BMap.Marker(point, {
				icon : myIcon
			});// 创建点
			map.addOverlay(marker); //增加点	
			pointArray[i] = new BMap.Point(json_data[i][0], json_data[i][1]);
			marker.addEventListener("click", addEvent);
		}

		map.setViewport(pointArray);

	}
</script>

<script type="text/javascript">
	//百度地图API功能
	var top_left_control = new BMap.ScaleControl({
		anchor : BMAP_ANCHOR_TOP_LEFT
	});// 左上角，添加比例尺
	var top_left_navigation = new BMap.NavigationControl(); //左上角，添加默认缩放平移控件

	// var map = new BMap.Map("allmap");
	var map = new BMap.Map("allmap", {
		enableMapClick : false
	});//构造底图时，关闭底图可点功能

	map.addControl(top_left_control);
	map.addControl(top_left_navigation);

	var xhm = new ActiveXObject("Microsoft.XMLHttp");
	xhm.open("GET", "../baiduMap/getPosition.do", false);
	xhm.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhm.send();
	var json = JSON.parse(xhm.responseText);
	var point = new BMap.Point(json.lng, json.lat);
	map.centerAndZoom(point, 13);

	var xhm = new ActiveXObject("Microsoft.XMLHttp");
	xhm.open("GET", "../baiduMap/location.do", false);
	xhm.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhm.send();
	var ticket = JSON.parse(xhm.responseText);
	var point = new BMap.Point(ticket.content.point.x, ticket.content.point.y);
	var str = "我的位置";
	var opts = {
		position : point
	// 指定文本标注所在的地理位置
	}
	var label = new BMap.Label(str, opts); // 创建文本标注对象
	label.setStyle({
		fontSize : "12px",
		height : "20px",
		lineHeight : "20px",
		fontFamily : "微软雅黑"
	});
	map.addOverlay(label);
	map.enableScrollWheelZoom(true);

	var geoc = new BMap.Geocoder();

	var xhm = new ActiveXObject("Microsoft.XMLHttp");
	xhm.open("GET", "../baiduMap/getAllAssetPosition.do", false);
	xhm.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhm.send();
	var data = JSON.parse(xhm.responseText);
	var ticket = data.rows;
	var total = document.getElementById("total");
	total.innerHTML = "&nbsp;&nbsp;总共 : " + data.total;

	var json_data = new Array();

	for (var i = 0; i < ticket.length; i++) {
		json_data[i] = [ ticket[i].lng, ticket[i].lat, ticket[i].address ];
	}

	var pointArray = new Array();

	for (var i = 0; i < json_data.length; i++) {
		var point = new BMap.Point(json_data[i][0], json_data[i][1]);
		var myIcon = new BMap.Icon("../img/blackPoint.jpg", new BMap.Size(10,
				30));
		var marker = new BMap.Marker(point, {
			icon : myIcon
		}); // 创建点
		map.addOverlay(marker); //增加点	
		pointArray[i] = new BMap.Point(json_data[i][0], json_data[i][1]);
		marker.addEventListener("click", addEvent);
	}

	map.setViewport(pointArray);

	function addEvent(e) {
		var p = e.target;
		//alert("marker的位置是" + p.getPosition().lng + "," + p.getPosition().lat);   
		var xhm = new ActiveXObject("Microsoft.XMLHttp");
		xhm.open("GET", "../baiduMap/getAssetGUIDByPosition.do?lng="
				+ p.getPosition().lng + "&lat=" + p.getPosition().lat, false);
		xhm.setRequestHeader("Content-type",
				"application/x-www-form-urlencoded");
		xhm.send();
		// alert(xhm.responseText);
		var data=JSON.parse(xhm.responseText);
		var obj=data.roomInfo;
		var url="../"+data.url;
		total=data.total;
		if(total==1){
		var content="<h4 style='margin:0 0 5px 0;padding:0.2em 0'> 资产名称 : "+obj.address+"</h4>"+
		"<img style='float:right;margin:4px' id='imgDemo' src="+url+" width='139' height='104'/>"+
		"<p>"+
   	 	" 管理分区 : "+obj.manageRegion+" "+
    	" 资产性质 : "+obj.roomProperty+" "+
    	" 资产编号 : "+obj.num+" </br>"+
    	" 面积 : "+obj.buildArea+" m<sup>2</sup> "+
    	" 租金 :"+obj.hire+" "+
    	"</p>"+"</div>";
		var infoWindow = new BMap.InfoWindow(content);  // 创建信息窗口对象
        map.openInfoWindow(infoWindow,new BMap.Point(e.point.lng, e.point.lat)); //开启信息窗口
		}else{
			rows=data.list;
	        div1=document.getElementById('div1')
			var tab="<table border=1 width=700>";
		        for(var i=0;i<rows.length;i++){
		        	var obj=rows[i];
		        	tab+="<tr>";
		        	tab+="<td> 资产名称 : "+obj.address+" </td>";
		        	tab+="<td> 管理分区 : "+obj.manageRegion+" </td>";
		        	tab+="<td> 资产性质 : "+obj.roomProperty+" </td>";
		        	tab+="<td> 资产编号 : "+obj.num+" </td>";
		        	tab+="<td> 面积 : "+obj.buildArea+" m<sup>2</sup> </td>";
		        	tab+="<td> 租金 :"+obj.hire+" </td>";	               
		            tab+="<td>"+"<img style='float:right;margin:4px' id='imgDemo' src="+url+" width='50' height='30'/>"+"</td>";
		            tab+="</tr>";
		        }    
		        tab+="</table>";
			
			var content="<h4 style='margin:0 0 5px 0;padding:0.2em 0'>  资产数量 : "+data.total+"</h4>"+
		"<p>"+
   	 	"  "+tab+" "+
    	"</p>"+"</div>";
		var infoWindow = new BMap.InfoWindow(content);  // 创建信息窗口对象
        map.openInfoWindow(infoWindow,new BMap.Point(e.point.lng, e.point.lat));
		}

	}

	var xhm = new ActiveXObject("Microsoft.XMLHttp");
	xhm.open("GET", "../baiduMap/getAllAsset.do?roomProperty="
			+ encodeURI(encodeURI("住宅房")), false);
	xhm.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhm.send();
	var data2 = JSON.parse(xhm.responseText);
	var ticket2 = data2.rows;
	var total = data2.total;

	addDeck2(ticket2);

	var xhm = new ActiveXObject("Microsoft.XMLHttp");
	xhm.open("GET", "../baiduMap/getAllHiddenAsset.do", false);
	xhm.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhm.send();
	var data3 = JSON.parse(xhm.responseText);
	var ticket3 = data3.rows;
	var total3 = data3.total;

//	addDeck3(ticket3);
	
	var opts = {
		width : 250, // 信息窗口宽度
		height : 120, // 信息窗口高度
		title : "资产详情", // 信息窗口标题
		enableMessage : true
	//设置允许信息窗发送短息
	};

	function openInfo(content, e) {
		var p = e.target;
		var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
		var infoWindow = new BMap.InfoWindow(content, opts); // 创建信息窗口对象 
		map.openInfoWindow(infoWindow, point); //开启信息窗口
	}

	function script() {
		map.clearOverlays();
		var xhm = new ActiveXObject("Microsoft.XMLHttp");
		xhm.open("GET", "../baiduMap/getAllAsset.do", false);
		xhm.setRequestHeader("Content-type",
				"application/x-www-form-urlencoded");
		xhm.send();
		var ticket = JSON.parse(xhm.responseText);
		addDeck(ticket);
	}
</script>
